import React, { useEffect, useState } from 'react'

export default function App() {
  const [count, setCount] = useState(0)
  useEffect(() => {
    // 副作用处理函数
    // 1. 初始化完毕会调用 => componentDidMount
    // 2. 任何状态发生变化的适合也会调用 => componentDidUpdate
    document.title = count
  })
  return (
    <div>
      <h3>{count}</h3>
      <button onClick={() => setCount(count + 1)}>+1</button>
    </div>
  )
}

/* export default class App extends React.Component {
  state = {
    count: 0,
  }
  componentDidMount() {
    document.title = this.state.count
  }
  componentDidUpdate() {
    document.title = this.state.count
  }
  handleClick = () => {
    this.setState({ count: this.state.count + 1 })
  }
  render() {
    return (
      <div>
        <h3>{this.state.count}</h3>
        <button onClick={this.handleClick}>+1</button>
      </div>
    )
  }
} */
